package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.IMyMessageService;
import com.ruoyi.web.domain.MyMessage;
import com.ruoyi.web.domain.UserFriend;
import com.ruoyi.web.service.IUserFriendService;
import com.ruoyi.web.utils.UserMsgUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * friendController
 *
 * @author ruoyi
 * @date 2024-04-24
 */
@RestController
@RequestMapping("/wx/friend")
public class UserFriendController extends BaseController {
    @Autowired
    private IUserFriendService userFriendService;
    @Autowired
    private IMyMessageService myMessageService;

    /**
     * 查询friend列表
     */
    @GetMapping("/list")
    public AjaxResult list(UserFriend userFriend) {
//        startPage();
        List<SysUser> friends = userFriendService.selectFriendsByUserId();
        return AjaxResult.success(friends);
//        return getDataTable(list);
    }

    /**
     * 新增friend
     */
    @Log(title = "friend", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserFriend userFriend) {
        int row = userFriendService.insertUserFriend(userFriend);
        if (row > 0) {
            // 添加成功
            return toAjax(row);
        }
        // 好友关系已经存在
        return AjaxResult.success("好友关系已存在");
    }

    /**
     * 修改friend
     */
    @Log(title = "friend", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserFriend userFriend) {
        return toAjax(userFriendService.updateUserFriend(userFriend));
    }

    /**
     * 删除friend
     */
    @Log(title = "friend", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userFriendService.deleteUserFriendByIds(ids));
    }
}
